<?php
/**
 * @Name: UserInfoSearch.php
 * @Author: yashuai<1762910894@qq.com>
 */

namespace App\Http\Search\Rbac;

use App\Http\Search\BaseSearch;
use App\Http\Model\Rbac\UserModel;
use HugCode\PhpUnits\Frame\Code\ConstCode;

class UserSearch extends BaseSearch
{

    /**
     * @Desc 用户列表搜索
     * @return array
     * @author yashuai<1762910894@qq.com>
     */
    public function index()
    {
        $where  = [
            'UserStatus' => _array_field($this->params, 'Status', ConstCode::BASIC_STATUS_NORMAL)
        ];
        $select = ['UserID', 'UserName', 'NickName', 'UserEmail', 'IsSuper', 'UserStatus', 'CreateTime'];
        $query  = UserModel::with(['role', 'role.role'])->where($where)->select($select);
        $result = $this->pageList($query);
        foreach ($result['list'] as &$val) {
            $val['RoleID']   = [];
            $val['RoleList'] = [];
            if ($val['IsSuper'] == ConstCode::IS_NO) {
                $val['RoleID']   = array_column($val['role'], 'RoleID');
                $val['RoleList'] = array_column($val['role'], 'role');
            }
            unset($val['role']);
        }
        return $result;
    }

}
